<?php
session_start();
include 'config.php';
$myfile = fopen("mylex.php", "w+") or die("Unable to open file!");
$userid = $_SESSION['userid'];
$lexid = $_SESSION['lexid'];

//$_SESSION["lextitle"] = $gotitle;
$query = "SELECT source, target, lexid FROM  map WHERE userid = '$userid'";
$result = mysqli_query($con, $query) or die("Could not SELECT * FROM lexsettings INNER JOIN context ON lexsettings.lexid = context.lexid");
$beginning = '<?php 
session_start();
include "config.php";
$userid = $_SESSION["userid"];
$gotitle = str_replace("_", " ",  $_GET["id"]);
$title = $_SESSION["lextitle"]; 
$lexid = $_SESSION["lexid"];
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="styles/styles.css">
<link href="http://fonts.googleapis.com/css?family=Oxygen:400,700,300" rel="stylesheet" type="text/css">
<script src="js/main.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.d3plus.org/js/d3.js"></script>
<script src="http://www.d3plus.org/js/d3plus.js"></script>
<base target="_parent" />
</head>
<body>
<?php include "mainFooter.php"; ?>
<div id="viz"></div>
<script>
 var focq = "<?php echo $title; ?>"
var lexid = "<?php echo $lexid; ?>"
 var connections = [';
fwrite($myfile,$beginning);
while ($rows = mysqli_fetch_assoc($result)) {
extract($rows);
$middle = json_encode($rows).",";
fwrite($myfile, $middle);
}
$end = ' ]


var attributes = [
    {"name": "Academic life", "hex": "#7f8c8d"},
	{"name": "Personal life", "hex": "#7f8c8d"},
	{"name": "Working life", "hex": "#7f8c8d"},
	{"name": "Critical thinking and problem solving",  "hex": "#FF7B66"},
	{"name": "Creativity and innovation", "hex": "#FFC640"},
	{"name": "Collaboration teamwork and leadership", "hex": "#FFDD40"},
	{"name": "Cross cultural understanding", "hex": "#ADFF40"},
	{"name": "Communication and media fluency", "hex": "#40D2FF"},
	{"name": "Computing and ICT fluency", "hex": "#8E40FF"},
	{"name": "Career and learning self reliance", "hex": "#DE40FF"},
  ]


 var visualization = d3plus.viz()
  .container("#viz")
    .type("rings")
    .id("name")
	.edges(connections) 	
    .focus(focq)
	.attrs(attributes)     
	.color("hex")
	.focus({"tooltip":false,}) 
	.draw()
  </script> 
<script>


 document.ondblclick = function(evt) {
    var evt=window.event || evt; // window.event for IE
    if (!evt.target) evt.target=evt.srcElement; // extend target property for IE
	
	var str = evt.target.__data__.name
	var replaced = str.split(" ").join("_");
	var lexid = "<?php echo $lexid; ?>"
	console.log(str);
if (str != "Academic life" && str !="Personal life" && str != "Working life" && str != "Critical thinking and problem solving" && str !="Collaboration teamwork and leadership" && str !="Cross cultural understanding" && str !="Communication and media fluency" && str != "Computing and ICT fluency" && str != "Career and learning self reliance"){
	parent.document.location.href = "http://www.lorettarose.co.uk/pinpoint/ilex.php?id="+replaced
	}
 }
     </script>';
fwrite($myfile, $end);
fclose($myfile);
header ("LOCATION:mylex.php");
?>
